package com.dsh.userSetting.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.dsh.storeManagement.entity.vo.AdminFranchiseLevelVo;
import com.dsh.userSetting.dao.AdminIntegralRuleDao;
import com.dsh.userSetting.entity.IntegralObtainingMethod;
import com.dsh.userSetting.entity.dto.AdminIntegralRuleDto;
import com.dsh.userSetting.entity.vo.AdminIntegralRuleVo;
import com.dsh.userSetting.service.AdminIntegralRuleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户设置权限规则(AdminIntegralRule)表服务实现类
 *
 * @author makejava
 * @since 2022-05-10 11:42:52
 */
@Service("adminIntegralRuleService")
public class AdminIntegralRuleServiceImpl implements AdminIntegralRuleService {
    @Resource
    private AdminIntegralRuleDao adminIntegralRuleDao;

//    @Override
//    public int insertRule(AdminIntegralRuleDto adminIntegralRuleDto) {
//        adminIntegralRuleDto.setConsumption((JSONObject.toJSONString(adminIntegralRuleDto.getConsumptions())));
//        adminIntegralRuleDto.setToStore((JSONObject.toJSONString(adminIntegralRuleDto.getToStores())));
//        adminIntegralRuleDto.setHomeProject((JSONObject.toJSONString(adminIntegralRuleDto.getHomeProjects())));
//        int i = adminIntegralRuleDao.insertRule(adminIntegralRuleDto);
//        return i;
//    }

    @Override
    public AdminIntegralRuleVo updateRole(AdminIntegralRuleDto adminIntegralRuleDto) {
        AdminIntegralRuleVo all = adminIntegralRuleDao.findAll();
        if (adminIntegralRuleDto!=null){
            if (all == null){
                adminIntegralRuleDto.setConsumption((JSONObject.toJSONString(adminIntegralRuleDto.getConsumptions())));
                adminIntegralRuleDto.setToStore((JSONObject.toJSONString(adminIntegralRuleDto.getToStores())));
                adminIntegralRuleDto.setHomeProject((JSONObject.toJSONString(adminIntegralRuleDto.getHomeProjects())));
                this.adminIntegralRuleDao.insertRule(adminIntegralRuleDto);
            }
            else {
                adminIntegralRuleDto.setConsumption((JSONObject.toJSONString(adminIntegralRuleDto.getConsumptions())));
                adminIntegralRuleDto.setToStore((JSONObject.toJSONString(adminIntegralRuleDto.getToStores())));
                adminIntegralRuleDto.setHomeProject((JSONObject.toJSONString(adminIntegralRuleDto.getHomeProjects())));
                this.adminIntegralRuleDao.updateRole(adminIntegralRuleDto);
            }
        }
        AdminIntegralRuleVo all1 = adminIntegralRuleDao.findAll();
        return all1;
    }

    @Override
    public IntegralObtainingMethod updateMother(IntegralObtainingMethod integralObtainingMethod) {
        IntegralObtainingMethod allMethod = adminIntegralRuleDao.findAllMethod();
        if (integralObtainingMethod!=null){
            if (allMethod==null){
                this.adminIntegralRuleDao.insertMethod(integralObtainingMethod);
            }
            else {
                this.adminIntegralRuleDao.updateMethod(integralObtainingMethod);
            }
        }
        IntegralObtainingMethod allMethod1 = adminIntegralRuleDao.findAllMethod();
        return allMethod1;
    }

//    @Override
//    public AdminIntegralRuleVo findAll() {
//        AdminIntegralRuleVo all = adminIntegralRuleDao.findAll();
//        return all;
//    }
}